package com.yang.file_explorer;

import android.app.Application;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.util.Log;

public class FeApp extends Application {

	private static final String TAG = FeApp.class.getSimpleName();

	private static Context sContext;

	@Override
	public void onCreate() {
		super.onCreate();
		sContext = getApplicationContext();
	}

	/**
	 * @return the Context of this application
	 */
	public static Context getAppContext() {
		if (sContext == null) {
			Log.e(TAG, "Global context not set");
		}
		return sContext;
	}

	/**
	 * @return true if this is the free version
	 */
	public static boolean isFreeVersion() {
		try {
			Context context = getAppContext();
			return context.getPackageName().contains("free");
		} catch (Exception swallow) {
		}
		return false;
	}

	/**
	 * Get the version from the manifest.
	 * 
	 * @return The version as a String.
	 */
	public static String getVersion() {
		Context context = getAppContext();
		String packageName = context.getPackageName();
		try {
			PackageManager pm = context.getPackageManager();
			return pm.getPackageInfo(packageName, 0).versionName;
		} catch (NameNotFoundException e) {
			Log.e(TAG, "Unable to find the name " + packageName
					+ " in the package");
			return null;
		}
	}
}
